<template>
  <div id="app">
    <router-view />
    <theme-picker />
  </div>
</template>

<script>
import ThemePicker from "@/components/ThemePicker";

export default {
  name: "App",
  components: {ThemePicker},
    metaInfo() {
        return {
            title: this.$store.state.settings.dynamicTitle && this.$store.state.settings.title,
            titleTemplate: title => {
                return title ? `${title} - ${process.env.VUE_APP_TITLE}` : process.env.VUE_APP_TITLE
            }
        }
    },
  created() {
    this.initWebSocket()
  },
methods:{
  initWebSocket() {
    this.websock = new WebSocket("ws://47.97.155.155:8080/webSocket/"+this.$store.getters.id)
    // this.websock = new WebSocket("ws://10.250.251.147:8080/webSocket/"+this.$store.getters.id)
    this.websock.onmessage = this.websocketOnMessage
    this.websock.onopen = this.websocketOnOpen
    this.websock.onerror = this.websocketOnError
    this.websock.onclose = this.websocketClose
  },
  // websocket连接后发送数据(send发送)
  websocketOnOpen() {
    console.log('websock已打开')
  },
  // 连接建立失败重连
  websocketOnError() {
    console.log("连接建立失败重连")
    this.initWebSocket()
  },
  // 数据接收
  websocketOnMessage(e) {
    console.log('数据接收', e)
    // debugger
    // console.log(this.websock.readyState)
    // this.$message.error(e.data)
    // console.log(e.data)

    alert("您收到一条来自"+`${JSON.parse(e.data).fromName}`+"的待办信息")
    this.websocketClose()
  },
  // 数据发送
  websocketSend(Data) {
    this.websock.send(Data)
  },
  // 关闭
  websocketClose(e) {
    console.log('断开连接', e)
  }


}

};
</script>
<style scoped>
#app .theme-picker {
  display: none;
}
</style>
